package org.smile.excel.jdbc;

import org.smile.dataset.Row;
import org.smile.expression.Context;
import org.smile.expression.DefaultContext;
import org.smile.expression.Engine;

public class WhereExpress extends ExcelSqlExpress<Boolean>{
	/**条件表达式*/
	protected String expression;
	//表达式解析上下文
	Context context;
	//是否是常量的条件语句
	Boolean consts;
	
	@Override
	public Boolean eval(Row row) {
		if(consts!=null){
			return consts;
		}
		if(context==null){
			context=new DefaultContext();
		}
		context.setRoot(row);
		return (Boolean) Engine.getInstance().evaluate(context, expression);
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}

	public void setConsts(Boolean consts) {
		this.consts = consts;
	}
	
	public boolean isConsts(){
		return this.consts!=null;
	}
	
	public boolean getConstsValue(){
		return consts;
	}
	
}
